package cn.dakaqi.services.impl;

import cn.dakaqi.dao.SysActivityTagDao;
import cn.dakaqi.entities.SysActivityTag;
import cn.dakaqi.services.SysActivityTagService;
import cn.dakaqi.utils.exception.ServiceRuntimeException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.persistence.DynamicSpecifications;

import java.util.List;

/**
 * Created by chunyang on 2016/4/18.
 */
@Component(value = "sysActivityTagService")
@Transactional
public class SysActivityTagServiceImpl implements SysActivityTagService
{
    @Autowired
    SysActivityTagDao sysActivityTagDao;
    @Override
    public void save(String param) throws ServiceRuntimeException
    {
        JSONObject jsonObject = JSON.parseObject(param);
        String name = jsonObject.getString("name");
        SysActivityTag sysActivityTag = new SysActivityTag(name);
        this.save(sysActivityTag);
    }

    @Override
    public void save(SysActivityTag sysActivityTag) throws ServiceRuntimeException
    {
        this.sysActivityTagDao.save(sysActivityTag);
    }

    @Override
    public List<SysActivityTag> findAll() throws ServiceRuntimeException
    {
        Specification<SysActivityTag> spec = DynamicSpecifications.bySearchFilter(null, SysActivityTag.class);
        List<SysActivityTag> list = this.sysActivityTagDao.findAll(spec);
        return list;
    }
}
